﻿//=====================================================================================================
// LocalizationLibrary
// The Localization Library is a collection of reusable software components that provide 
// support for localization. This library enables you to localize WPF, Silverlight and WP7 applications.
// (http://localizationlibrary.codeplex.com)
//=====================================================================================================
// Author: Nicola Gallo (Website: www.nicola.gallo.name, Email: nicolagmt@hotmail.it) 
//=====================================================================================================

namespace HelloWorld.Startup
{
    //.NET References
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;

    //LocalizationLibrary References
    using LocalizationLibrary;

    //HelloWorld References
    using HelloWorld.Startup.Localization;
    using HelloWorld.Startup.MVVM;
    using HelloWorld.Startup.Views;

    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        //Fields

        private WaitingPanel _waitingPanel;

        //Constructors

        /// <summary>
        /// Default constructor.
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();

            //Initializes the localization manager.
            LocalizationManager.AppLocalizationProviderType = typeof(HelloWorldServiceLocalizationProvider);
            LocalizationManager.CurrentLanguage = (Language)"en";
            LocalizationManager.Initialize();

            //Initialize view.
            ApplicationManager.SetCurrentView<HeaderView>(this.headerContentControl);
            ApplicationManager.SetCurrentView<MenuView>();
        }
        
        //Properties

        /// <summary>
        /// Gets the view's content control.
        /// </summary>
        public ContentControl ViewContentControl 
        {
            get 
            {
                return this.viewContentControl;
            }
        }

        /// <summary>
        /// Gets the waiting panel
        /// </summary>
        public WaitingPanel WaitingPanel
        {
            get 
            {
                if (this._waitingPanel == null)
                {
                    this._waitingPanel = new WaitingPanel();
                    this.grdPanel.Children.Add(this._waitingPanel);
                    Grid.SetRow(this._waitingPanel, 0);
                    Grid.SetRowSpan(this._waitingPanel, 2);
                }
                return this._waitingPanel; 
            }
        }

        //Constructors

        /// <summary>
        /// Called when window is loade.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            Binding binding = new Binding("IsLocalizing");
            binding.Source = LocalizationLibrary.LocalizationManager.EngineInfo;
            binding.Converter = new Converters.BoolVisibilityConverter();
            this.WaitingPanel.SetBinding(UserControl.VisibilityProperty, binding);

            WPF.Themes.ThemeManager.ApplyTheme(App.Current, "BureauBlue");
        }

    }
}